package educar.gui;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JLayeredPane;
import javax.swing.JButton;
import educar.controllers.AdminDocenteMateriaController;
import educar.models.Materia;


public class AdminDocenteMateriaView extends JFrame implements IView
{

    private static final long serialVersionUID = 1L;

    public static final String ASIGNAR = "Asignar";
    private final JLayeredPane ADMateriaPane = new JLayeredPane();

    private JPanel ADMateriaContentPane;

    private JComboBox ADMateriaMateriaBox;
    private JCheckBox ADMateriaResponsableBox;

    GenericListener listener;


    /**
     * Create the frame.
     */
    public AdminDocenteMateriaView()
    {

        listener = new GenericListener();
        this.setVisible(true);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setBounds(100, 100, 450, 300);

        ADMateriaContentPane = new JPanel();

        String[] materias =  Materia.getAllMateriasArray();

        ADMateriaContentPane.setBackground(UIManager.getColor("List.dropCellBackground"));
        ADMateriaContentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        ADMateriaContentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(ADMateriaContentPane);
        ADMateriaContentPane.add(ADMateriaPane, BorderLayout.CENTER);

        JLabel ADMateriaMateriaLabel = new JLabel("Materia");
        ADMateriaMateriaLabel.setBounds(12, 43, 70, 15);
        ADMateriaPane.add(ADMateriaMateriaLabel);

        ADMateriaMateriaBox = new JComboBox(materias);
        ADMateriaMateriaBox.setBounds(113, 38, 224, 24);
        ADMateriaPane.add(ADMateriaMateriaBox);

        JLabel ADMateriaAsignacionMateriaLabel = new JLabel("Asignacion de materia");
        ADMateriaAsignacionMateriaLabel.setBounds(12, 0, 190, 15);
        ADMateriaPane.add(ADMateriaAsignacionMateriaLabel);

        ADMateriaResponsableBox = new JCheckBox("Responsable");
        ADMateriaResponsableBox.setBounds(113, 85, 120, 24);
        ADMateriaPane.add(ADMateriaResponsableBox);


        JButton ADMateriaAsignarButton = new JButton(ASIGNAR);
        ADMateriaAsignarButton.setBounds(220, 193, 117, 25);
        ADMateriaPane.add(ADMateriaAsignarButton);


        AdminDocenteMateriaController  c = new AdminDocenteMateriaController();
        c.setView(this);
        listener.associate(ADMateriaAsignarButton, c);
    }

    public String getCodMateriaSelected()
    {
    	String materia = (String)ADMateriaMateriaBox.getSelectedItem();
        return (materia.substring(materia.lastIndexOf('-')+1).trim());
        
    }

    public Boolean getResponsable()
    {
        return ADMateriaResponsableBox.isSelected();
    }

    public void close()
    {
        this.setVisible(false);
    }


    public void present(String model)
    {
        JOptionPane.showMessageDialog(null, model);

    }

}
